import './index.less';
import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import {useDispatch,useHistory,useLocation} from 'umi';
import {IloginItem} from '@/utils/interface';


export default function LoginPages() {
  const dispatch = useDispatch();
  const history = useHistory();
  const location = useLocation();
  const onFinish = (payload: IloginItem) => {
    console.log('Received values of form: ', payload);
    let result = dispatch({
      type: 'login/login',
      payload,
    });
    ((result as never) as Promise<any>).then((res) => {
      let {
        query: { from },
      } = (location as unknown) as { query: { from: string } };
      console.log((location as unknown) as { query: { from: string } });
      history.replace(decodeURIComponent(from) || '/');
    });
  };
  return (
    <div className="Login">
      <div className="Login_from">
        <Form
          name="normal_login"
          className="login-form"
          initialValues={{ remember: true }}
          onFinish={onFinish}
        >
          <Form.Item
            name="user_name"
            rules={[{ required: true, message: 'Please input your Username!' }]}
          >
            <Input
              prefix={<UserOutlined className="site-form-item-icon" />}
              placeholder="请输入用户名"
            />
          </Form.Item>
          <Form.Item
            name="user_pwd"
            rules={[{ required: true, message: 'Please input your Password!' }]}
          >
            <Input
              prefix={<LockOutlined className="site-form-item-icon" />}
              type="password"
              placeholder="请输入用户密码"
            />
          </Form.Item>
          <Form.Item className="ant-height">
            <Form.Item name="remember" valuePropName="checked" noStyle>
              <Checkbox>记住密码</Checkbox>
            </Form.Item>

            <a className="login-form-forgot" href="">
              忘记密码
            </a>
          </Form.Item>

          <Form.Item className="ant-button">
            <Button
              type="primary"
              htmlType="submit"
              className="login-form-button"
            >
              登录
            </Button>
          </Form.Item>
        </Form>
      </div>
    </div>
  );
}
